package com.auxgroup.hr.front.site.co.common;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.auxgroup.hr.front.site.vo.person.JobCodeListRespVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.auxgroup.hr.front.commons.enums.WfTypeEnum;
import com.auxgroup.hr.front.commons.vo.BaseResponseVO;
import com.auxgroup.hr.front.dao.domain.PsCPrcTypeVw;
import com.auxgroup.hr.front.dao.domain.PsRsActDtlTbl;
import com.auxgroup.hr.front.dao.domain.Psxlatitem;
import com.auxgroup.hr.front.dozer.IObjectMapper;
import com.auxgroup.hr.front.service.comm.SysDictService;
import com.auxgroup.hr.front.site.co.BaseCO;
import com.auxgroup.hr.front.site.vo.person.JobCodeListRespVO;

/**
 * 字典信息CO
 * @author wangchangyun
 * @version 创建时间：180523
 */
@RestController
@RequestMapping("${auxgroup.hr.contextPath}/sysdict")
public class SysDictCO extends BaseCO {

	private static final Logger logger = LoggerFactory.getLogger(SysDictCO.class);

	@Autowired
	public SysDictService sysDictService;

	@Resource(name = "dozerMapper")
	protected IObjectMapper objectMapper;

	/**
	 * 获取字典信息值
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getOne")
	public BaseResponseVO getOne(String fileName,String fileValue) {
		logger.info("sysdict param= {}", fileName);
		Psxlatitem item = sysDictService.getSysDict(fileName, fileValue);
		return buildRespone(item,false);
	}
	
	
	/**
	 * 获取字典信息值
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getAll")
	public BaseResponseVO getAll(String fileName) {
		logger.info("sysdict param= {}", fileName);
		List<Psxlatitem> items = sysDictService.getSysDict(fileName);
		return buildRespone(items,false);
	}
	
	/**
	 * 查询所有的转正类型
	 * @return
	 */
	@GetMapping(value = "/getPrcType")
	public BaseResponseVO getPrcType(){
		List<PsCPrcTypeVw> items = sysDictService.getPrcTypes();
		return buildRespone(items,false);
	}
	
	/**
	 * 获取岗位信息
	 * @param hireId
	 * @return
	 */
	@GetMapping(value = "/getJobdesc")
	public BaseResponseVO getJob(String setId,String jobCode) {
		String  jobdesc = sysDictService.getJobDesc(setId,jobCode);
		return buildRespone(jobdesc);
	}
	
	/**
	 * 获取岗位列表
	 * @param setId
	 * @param jobCode
	 * @return
	 */
	@GetMapping(value = "/getJoblist")
	public BaseResponseVO getJobList(String setId) {
		List<Object[]> results = sysDictService.getJobListBySetid(setId);
		JobCodeListRespVO respVO = null;
		List<JobCodeListRespVO> respVOs = new ArrayList<JobCodeListRespVO>();
		if(results!=null&&!results.isEmpty()){
			for (Object[] str : results) {
				respVO = new JobCodeListRespVO();
				respVO.setJobcode(String.valueOf(str[0]));
				respVO.setDescr(String.valueOf(str[1]));
				respVO.setRsJobLevel(String.valueOf(str[2]));
				respVO.setcFunction(String.valueOf(str[3]));
				respVO.setcFunctionType(String.valueOf(str[4]));
				respVO.setcFunctionSub(String.valueOf(str[5]));
				respVOs.add(respVO);
			}
			return buildRespone(respVOs,false);
		}
		return buildRespone();
	}
	
	
	
	/**
	 * 获取离职原因列表
	 * @param setId
	 * @param jobCode
	 * @return
	 */
	@GetMapping(value = "/getActionResons")
	public BaseResponseVO getActionResons() {
		List<Object[]> results = sysDictService.getActionResons(WfTypeEnum.WF_STYPE_TER.getType());
		Map<String, String> respVO = null;
		List<Map<String, String>> respVOs = new ArrayList<Map<String, String>>();
		if(results!=null&&!results.isEmpty()){
			for (Object[] str : results) {
				respVO = new HashMap<String, String>();
				respVO.put("actionReson", String.valueOf(str[0]));
				respVO.put("descr", String.valueOf(str[1]));
				respVOs.add(respVO);
			}
			return buildRespone(respVOs,false);
		}
		return buildRespone();
	}
	
	
	/**
	 * 获取离职详情列表
	 * @param setId
	 * @param jobCode
	 * @return
	 */
	@GetMapping(value = "/getTerDetail")
	public BaseResponseVO getTerDetail(String actionReason) {
		List<PsRsActDtlTbl> results = sysDictService.getTerDetails(actionReason);
		return buildRespone(results,false);
	}
	

}
